#include "rblinkConvert.h"
#include "qdesktopservices.h"
#include "convert.h"
rblinkConvert::rblinkConvert(QWidget *parent)
    : QWidget(parent)
{
    ui.setupUi(this);

	connect(ui.pushButton_Start, SIGNAL(clicked()), this, SLOT(onStartButton()));
	connect(ui.pushButton_Clear, SIGNAL(clicked()), this, SLOT(onClearButton()));
	connect(ui.pushButton_Setting, SIGNAL(clicked()), this, SLOT(onSettingButton()));
	connect(ui.pushButton_Devices, SIGNAL(clicked()), this, SLOT(onDeviceButton()));
	connect(ui.pushButton_Logfolder, SIGNAL(clicked()), this, SLOT(onlogfolderButton()));
	connect(this, SIGNAL(AppendText(QString)), this, SLOT(SlotAppendText(QString)));
	convertSvr::Instance().logevent([=](const char* data, int len) {
		//ui.textBrowser->append(QString(data));
		Append(QString(data));
		});
}

rblinkConvert::~rblinkConvert()
{}

void rblinkConvert::Append(const QString& text)
{
	emit AppendText(text);
}

void rblinkConvert::onStartButton()
{
	if ("Start" == ui.pushButton_Start->text().toStdString())
	{
		ui.pushButton_Start->setText("Stop");
		ui.textBrowser->append("it's start");
		convertSvr::Instance().startSvr();

	}
	else
	{
		ui.pushButton_Start->setText("Start");
		ui.textBrowser->append("it's stop");
		convertSvr::Instance().stopSvr();
	}
}

void rblinkConvert::onClearButton()
{
	ui.textBrowser->clear();
}

void rblinkConvert::onSettingButton()
{
	configui.show();
}

void rblinkConvert::onDeviceButton()
{
	devicelistui.show();
}


void rblinkConvert::onlogfolderButton()
{
	//QDesktopServices::openUrl(QUrl::fromLocalFile("./"));
	QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(convertSvr::Instance().getLogPath()) ));
}

void rblinkConvert::SlotAppendText(const QString& text)
{
	ui.textBrowser->append(text);
}